package com.dissertation.utils;

import com.dissertation.model.Assets;

import java.lang.reflect.Field;

public class CompleteRateHelper {

    /**
     * 获取的值偏大
     * @param assets
     * @return
     * @throws IllegalAccessException
     */
    public static double getCompleteRate( Assets assets ) throws IllegalAccessException {
        Field[] fields = assets.getClass().getDeclaredFields();
        double completeColumnNum = 0;
        double total = 0;
        for ( Field field :
                fields ) {
            field.setAccessible( true );
            Object o = field.get( assets );
            if ( o != null ) {
                completeColumnNum ++;
            }
            total++;
        }
        fields = assets.getClass().getSuperclass().getDeclaredFields();

        for ( Field field :
                fields ) {
            field.setAccessible( true );
            Object o = field.get( assets );
            if ( o != null ) {
                completeColumnNum ++;
            }
            total++;
        }


        return completeColumnNum / total;
    }
}
